<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>易抽奖-抽奖</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="index.css" type="text/css">
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-lg-3 visible-xs-*"></div>
        <div class="col-lg-6" style="background-color:#DCDCDC"><br>
            <p class="font">活动名称</p>
            <div align="center">
                <p class="button3" id="lotteryname"></p>
                <img src="./images/timg.png" width="200px" ; height="200px" ; style="position:center; " id="img"/> <br><br>
                <button id="angle" class="button2 theme-benginlottery" onclick="doLottery()">抽奖</button>
                <br><br>
                <!--<button class="button2">分享给小伙伴</button><br><br><br><br>-->
            </div>
            <!-- 初始页面展示 -->
            <div class="theme-popover">
                <div class="theme-poptit"><br>
                    <p class="font" id="again">请输入您的活动邀请码:</p>
                </div>
                <br>
                <div align="center">
                    <input class="input2" type="number" id="passcode"/><br><br><br><br>
                    <button class="button4 " id="yes">确定</button>
                    <button class="button5" onclick="window.open('index.html')">返回</button>
                </div>
            </div>
            <!-- 抽奖结果 -->
            <div class="theme-benginlottery">
                <div class="theme-popover2">
                    <div class="theme-poptit2"><br>
                        <p class="font">抽奖结果为：</p>
                    </div>
                    <br>
                    <div>
                        <p class="font" id="lotteryresult"></p><br><br>
                        <button class="button6" onclick="window.open('index.html')">返回主页</button>
                    </div>
                </div>
            </div>
            <!--页面灰色-->
            <div class="theme-popover-mask"></div>
        </div>
        <div class="col-lg-3 visible-xs-*"></div>
    </div>
</div>
</body>
<script>
    var getid = window.location.href.split('=')[1];
    $(document).ready(function () {
        //初始页面展示
        $('.theme-popover-mask').fadeIn(100);
        $('.theme-popover').slideDown(200);
        //展示抽奖名称
        $.post("http://yb.upc.edu.cn:8084/lottery/findone",
            {
                Authorization: localStorage.getItem("testtoken"),
                lotteryId: getid
            },
            function (data) {
                document.getElementById("lotteryname").innerHTML = data.object.lotteryname
            })

        //关闭框
        function guan() {
            $('.theme-popover-mask').fadeOut(100);
            $('.theme-popover').slideUp(200);
        }

        //判断抽奖码是否正确
        $("button#yes").click(function () {
            $.post("http://yb.upc.edu.cn:8084/lottery/ispass",
                {
                    Authorization: localStorage.getItem("testtoken"),
                    lotteryId: getid,
                    passcode: document.getElementById('passcode').value
                },
                function (data) {
                    if (data.code == 1) {
                        guan()
                    }
                    //不正确时展示重新输入
                    else {
                        $('p#again').text("输入错误!请再次输入:")
                        $('input#passcode').val("");
                    }
                })
        })
    });
    //抽奖按钮弹出框展示奖品
    function doLottery() {
        $('.theme-popover-mask').fadeIn(100);
        $('.theme-popover2').slideDown(200);
        $.get("http://yb.upc.edu.cn:8084/lottery/dolottery",
            {
                Authorization: localStorage.getItem("testtoken"),
                lotteryId: getid
            },
            function (data) {
                message = data.msg
                if (data.code == -1) {
                    document.getElementById("lotteryresult").innerHTML = message
                }
                else if (data.code == 0)
                    document.getElementById("lotteryresult").innerHTML = "抽奖出错，请稍候再来~"
                else if (data.code == -2)
                    document.getElementById("lotteryresult").innerHTML = message
                else
                    document.getElementById("lotteryresult").innerHTML = "恭喜你获得:<br>" + data.object.prizeName
            }
        )
    }
</script>
</html>


